home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / Mac gperf 1.9.cpt / Mac gperf 1.9 / src / options.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-09  |  5.5 KB  |  145 lines  |  [TEXT/KAHL]

  1. /* Handles parsing the Options provided to the user.
  2.  
  3.    Copyright (C) 1989 Free Software Foundation, Inc.
  4.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  5.  
  6. This file is part of GNU GPERF.
  7.  
  8. GNU GPERF is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GNU GPERF is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU GPERF; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. /* This module provides a uniform interface to the various Options available
  23.    to a user of the Perfect.hash function generator.  In addition to the
  24.    run-time Options, found in the Option_Type below, there is also the
  25.    hash table Size and the Keys to be used in the hashing.
  26.    The overall design of this module was an experiment in using C++
  27.    classes as a mechanism to enhance centralization of option and
  28.    and error handling, which tend to get out of hand in a C program. */
  29.  
  30. #ifndef _options_h
  31. #define _options_h
  32. #define _H_options
  33.  
  34. #include <stdio.h>
  35. #include "prototype.h"
  36.  
  37. /* Enumerate the potential debugging Options. */
  38.  
  39. enum option_type 
  40. {
  41.     DEBUG            = 01,            /* Enable debugging (prints diagnostics to Std_Err).    */
  42.     ORDER            = 02,            /* Apply ordering heuristic to speed-up search time.    */
  43.     ANSI            = 04,            /* Generate ANSI prototypes.                            */
  44.     ALLCHARS        = 010,            /* Use all characters in hash function.                    */
  45.     GNU                = 020,            /* Assume GNU extensions (primarily function inline).    */
  46.     TYPE            = 040,            /* Handle user-defined type structured keyword input.    */
  47.     RANDOM            = 0100,            /* Randomly initialize the associated values table.        */
  48.     DEFAULTCHARS    = 0200,            /* Make default char positions be 1,$ (end of keyword).    */
  49.     SWITCH            = 0400,            /* Generate switch output to save space.                */
  50.     POINTER            = 01000,        /* Have in_word_set function return pointer, not boolean. */
  51.     NOLENGTH        = 02000,        /* Don't include keyword length in hash computations.    */
  52.     LENTABLE        = 04000,        /* Generate a length table for string comparison.        */
  53.     DUP                = 010000,        /* Handle duplicate hash values for keywords.            */
  54.     FAST            = 020000,        /* Generate the hash function ``fast.''                    */
  55.     NOTYPE            = 040000,        /* Don't include user-defined type definition            *
  56.                                      * in output -- it's already defined elsewhere.            */
  57.     COMP            = 0100000,        /* Generate strncmp rather than strcmp.                    */
  58.     GLOBAL            = 0200000,        /* Make the keyword table a global variable.            */
  59.     CONST            = 0400000        /* Make the generated tables readonly (const).            */
  60. };
  61.  
  62.  
  63. /* Define some useful constants. */
  64.  
  65. /* Max size of each word's key set. */
  66. #define MAX_KEY_POS (128 - 1)
  67.  
  68. /* Signals the start of a word. */
  69. #define WORD_START 1           
  70.  
  71. /* Signals the end of a word. */
  72. #define WORD_END 0             
  73.  
  74. /* Signals end of the key list. */
  75. #define EOS MAX_KEY_POS        
  76.  
  77. /* Returns TRUE if option O is enabled. */
  78. #define OPTION_ENABLED(OW,O) (OW.option_word & (int)O)
  79.  
  80. /* Enables option O in OPTION_WORD. */
  81. #define SET_OPTION(OW,O) (OW.option_word |= (int)O)
  82.  
  83. /* Disable option O in OPTION_WORD. */
  84. #define UNSET_OPTION(OW,O) (OW.option_word &= ~(int)(O))
  85.  
  86. /* Returns total distinct key positions. */
  87. #define TOTAL_POSITIONS(O) (O.total_key_positions)
  88.  
  89. /* Initializes the key Iterator. */
  90. #define RESET(O) (O.key_pos = 0)
  91.  
  92. /* Returns current key_position and advances index. */
  93. #define GET(O) (O.key_positions[O.key_pos++])
  94.  
  95. /* Sets the size of the table size. */
  96. #define SET_ASSO_MAX(O,R) (O.size = (R))
  97.  
  98. /* Returns the size of the table size. */
  99. #define GET_ASSO_MAX(O) (O.size)
  100.  
  101. /* Returns the jump value. */
  102. #define GET_JUMP(O) (O.jump)
  103.  
  104. /* Returns the iteration value. */
  105. #define GET_ITERATIONS(O) (O.iterations)
  106.  
  107. /* Returns the lookup function name. */
  108. #define GET_FUNCTION_NAME(O) (O.function_name)
  109.  
  110. /* Returns the keyword key name. */
  111. #define GET_KEY_NAME(O) (O.key_name)
  112.  
  113. /* Returns the hash function name. */
  114. #define GET_HASH_NAME(O) (O.hash_name)
  115.  
  116. /* Returns the initial associated character value. */
  117. #define INITIAL_VALUE(O) (O.initial_asso_value)
  118.  
  119. /* Class manager for gperf program options. */
  120.  
  121. typedef struct options
  122. {
  123.     int            option_word;           /* Holds the user-specified Options. */
  124.     int            total_key_positions;   /* Total number of distinct key_positions. */
  125.     int            size;                  /* Range of the hash table. */
  126.     int            key_pos;               /* Tracks current key position for Iterator. */
  127.     int            jump;                  /* Jump length when trying alternative values. */
  128.     int            initial_asso_value;    /* Initial value for asso_values table. */
  129.     int            argument_count;        /* Records count of command-line arguments. */
  130.     int            iterations;            /* Amount to iterate when a collision occurs. */
  131.     char **        argument_vector;       /* Stores a pointer to command-line vector. */
  132.     char *        function_name;         /* Name used for generated lookup function. */
  133.     char *        key_name;              /* Name used for keyword key. */
  134.     char *        hash_name;             /* Name used for generated hash function. */
  135.     char        key_positions[MAX_KEY_POS]; /* Contains user-specified key choices. */
  136. } OPTIONS;
  137.  
  138. extern    void    options_init( int argc, char *argv[] );
  139. extern    void    options_destroy( void );
  140. extern    void    print_options( void );
  141.  
  142. extern    OPTIONS        option;
  143.  
  144. #endif /* _options_h */
  145.